package com.ruoyi.quartz.task;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.phone.domain.TelManageNew;
import com.ruoyi.system.phone.mapper.TelManageNewMapper;
import com.ruoyi.system.telManage.service.ITelManageHistoryService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class TelManageTask {

    @Autowired
    private TelManageNewMapper telManageNewMapper;
    @Autowired
    private ITelManageHistoryService telManageHistoryService;
    /**
     * 盼之接口刷新
     */
    @Scheduled(cron = "0 0 * * * ?")
    public void telTask() {
        List<TelManageNew> telManages = telManageNewMapper.selectTask();
        if (CollectionUtils.isEmpty(telManages)) {
            return;
        }
        for (TelManageNew telManage : telManages) {
            TelManageNew manage = new TelManageNew();
            manage.setId(telManage.getId());
            manage.setIsUse(0);
            manage.setUseType(0L);
            manage.setUseTime(0);
            manage.setUseImg("");
            manage.setUseRemark("");
            telManageNewMapper.updateTelManageNew(manage);


            Map<String, Object> params = new HashMap<>();
            params.put("userId", 1L);
            params.put("operator", "系统操作");
            params.put("status", "转可用");
            params.put("telId", telManage.getId());
            params.put("reason", telManage.getTel());
            params.put("bindAccount", telManage.getBindAccount());
            params.put("useTime", telManage.getUseTime());
            telManageHistoryService.addOperator(params);
        }
    }
}